/*
 ------------------------------------------------------------------------------
 Copyright (C) 2006-2007 Team Blur.

 This file is part of the Quantum Engine source code.

 The Quantum Engine source code is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or (at your
 option) any later version.

 The Quantum Engine source code is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 more details.

 You should have received a copy of the GNU General Public License along with
 the Quantum Engine source code; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 ------------------------------------------------------------------------------
*/


// game.h -- types and defines shared by both game modules


#ifndef __GAME_H__
#define __GAME_H__


#include "../interface/engine_interface.h"


#define GAME_NAME					"Quantum Engine"

#define ENTITYNUM_BITS				12

#define ENTITYNUM_NONE				(MAX_ENTITIES - 1)
#define ENTITYNUM_WORLD				(MAX_ENTITIES - 2)
#define ENTITYNUM_MAX_NORMAL		(MAX_ENTITIES - 2)

// Per-level limits
#define MAX_GAME_ANIMATIONS			1024
#define MAX_GAME_MODELS				1024
#define MAX_GAME_CLIP_MODELS		1024
#define MAX_GAME_MATERIALS			1024
#define MAX_GAME_SOUND_SHADERS		1024

// Quantum Engine engine framework
extern odMemory_t *			odMemory;
extern odFileSystem_t *		odFileSystem;
extern odCmdSystem_t *		odCmdSystem;
extern odCVarSystem_t *		odCVarSystem;
extern odParser_t *			odParser;
extern odSystem_t *			odSystem;
extern odCollision_t *		odCollision;
extern odRenderer_t *		odRenderer;
extern odSound_t *			odSound;
extern odEditor_t *			odEditor;

/*
 ==============================================================================

 GAME PROTOCOL

 ==============================================================================
*/

#define	GAME_PROTOCOL_VERSION		4

#define MAX_SNAPSHOT_ENTITIES		1024

// Config strings are a general means of communicating variable length strings
// from the server to all connected clients.
// A config string can have at most MAX_STRING_LENGTH characters.
#define MAX_CONFIG_STRINGS			8192

#define CS_LEVEL_NAME				0
#define CS_LEVEL_START_TIME			1
#define CS_MOTD						2

#define CS_CLIENTS					32
#define CS_ANIMATIONS				(CS_CLIENTS + MAX_CLIENTS)
#define CS_MODELS					(CS_ANIMATIONS + MAX_GAME_ANIMATIONS)
#define CS_CLIP_MODELS				(CS_MODELS + MAX_GAME_MODELS)
#define CS_MATERIALS				(CS_CLIP_MODELS + MAX_GAME_CLIP_MODELS)
#define CS_SOUND_SHADERS			(CS_MATERIALS + MAX_GAME_MATERIALS)
#define CS_GENERAL					(CS_SOUND_SHADERS + MAX_GAME_SOUND_SHADERS)

// A game state contains information about the current game.
// It is only transmitted to clients when they connect to the server, but some
// parts of it (such as config strings) can also be updated during gameplay.
#define GS_START_CONFIG_STRINGS		0
#define GS_END_CONFIG_STRINGS		0 + (MAX_CONFIG_STRINGS - 1)

#define GS_START_BASELINES			MAX_CONFIG_STRINGS
#define GS_END_BASELINES			MAX_CONFIG_STRINGS + (MAX_ENTITIES - 1)

// The playerState_t structure contains information needed by both the client
// and server to predict player motion and actions.
// This is a full superset of entityState_t as it is used by players, so if a
// playerState_t is transmitted, the entityState_t can be fully derived from
// it.
typedef struct {
	int						pmType;
	int						pmFlags;
	int						pmTime;

	odVec3					origin;
	odVec3					velocity;
	odAngles				angles;

	int						deltaAngles[3];		// Add to userCmd->angles to get view direction

	float					gravity;
	float					speed;
	float					sprintSpeedScale;

	int						clientNum;

	int						userCmdTime;

	int						groundEntity;		// ENTITYNUM_NONE == in air
} playerState_t;

// The entityState_t structure contains information conveyed from the server in
// an update message about entities that the client will need to render in some
// way.
// Different types may use the information in different ways.
// The messages are delta compressed, so it doesn't really matter if the
// structure size is fairly large.
typedef enum {
	ET_GENERAL,
	ET_LIGHT,
	ET_SPEAKER
} entityType_t;

typedef struct {
	entityType_t			type;
	int						flags;

	int						number;

	odVec3					origin;
	odVec3					center;
	odAngles				angles;

	odVec3					radius;

	float					fovX;
	float					fovY;
	float					falloffRange;

	bool					projected;
	bool					parallel;
	bool					noShadows;

	int						detailLevel;

	int						modelIndex;
	int						clipModelIndex;

	int						materialIndex;
	int						soundShaderIndex;

	float					materialParms[MAX_MATERIAL_PARMS];

	int						solidBox;			// Used only if it doesn't have a clip model (0 == no collision at all)
	int						solidContents;
} entityState_t;

/*
 ==============================================================================

 GAME HEADERS

 ==============================================================================
*/

#include "anim/anim.h"

#include "physics/physics_player.h"


#endif	// __GAME_H__
